package au.com.georgi.wave.matcher;

import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.wave.api.Range;

public class PatternMatcher {

    private static final Logger log = Logger.getLogger(PatternMatcher.class.getName());

    public static String getURL(String pattern, String inputStr) {
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(inputStr);
        if (m.find()) {
            String match = m.group();
            log.warning("Found URL: " + match);
            return match;
        }
        log.warning("Did not find URL for input string: " + inputStr);
        return null;
    }

    public static Range getRange(String pattern, String inputStr) {
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(inputStr);
        if (m.find()) {
            return new Range(m.start(), m.end());
        }
        return null;
    }

}
